package com.hollysys.hollimsa.biz.istio.virtualservice.dao;

import me.snowdrop.istio.api.networking.v1beta1.VirtualService;
import me.snowdrop.istio.client.IstioClient;
import me.snowdrop.istio.client.internal.operation.networking.v1beta1.VirtualServiceOperationImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 路由规则k8s操作
 * @author wangyuxi
 * @date 2020/11/10
 **/
@Component
public class VirtualServiceDao {

    @Autowired
    private IstioClient istioClient;


    public VirtualService createOrReplaceVirtualservice(VirtualService vs,String namespace) {
        return istioClient.v1beta1VirtualService().inNamespace(namespace).createOrReplace(vs);
    }

    public VirtualServiceOperationImpl queryVirtualService(String namespace) {
        return (VirtualServiceOperationImpl) istioClient.v1beta1VirtualService().inNamespace(namespace);
    }

    public boolean deleteVirtualService(String name, String namespace) {
        return istioClient.v1beta1VirtualService().inNamespace(namespace).withName(name).delete();
    }
}
